import { BaseLoader } from "./BaseLoader";
import { Log } from "../../debug/Log";
type int = number;
//class SWFLoader
    
    export  class SWFLoader extends BaseLoader
    {
       

        public /* override */ getClass(): Class
        {
            return SWFLoader;
        }

        public get clip(): Object /* flash.display.Sprite */
        {
            return this._clip;
        }

        public get appDomain(): Object /* flash.system.ApplicationDomain */
        {
            return this._appDomain;
        }

        public getExportedAsset(arg1: string): Object
        {
            if (null == this._appDomain) 
            {
                throw new Error("not initialized");
            }
            var loc1=this.getAssetClass(arg1);
            if (loc1 != null) 
            {
                return new loc1();
            }
            return null;
        }

        public getAssetClass(arg1: string): Class
        {
            if (null == this._appDomain) 
            {
                throw new Error("not initialized");
            }
            if (this._appDomain.hasDefinition(arg1)) 
            {
                return this._appDomain.getDefinition(arg1) as Class;
            }
            return null;
        }

        public findMaxFrames(arg1: Object /* flash.display.MovieClip */, arg2: int): int
        {
            var loc2=null;
            var loc1=0;
            while (loc1 < arg1.numChildren) 
            {
                if (loc2 = arg1.getChildAt(loc1) as Object /* flash.display.MovieClip */) 
                {
                    arg2 = Math.max(arg2, loc2.totalFrames);
                    this.findMaxFrames(loc2, arg2);
                }
                ++loc1;
            }
            return arg2;
        }

        public advanceChildClips(arg1: Object /* flash.display.MovieClip */, arg2: int): void
        {
            var loc2=null;
            var loc1=0;
            while (loc1 < arg1.numChildren) 
            {
                if (loc2 = arg1.getChildAt(loc1) as Object /* flash.display.MovieClip */) 
                {
                    if (loc2.totalFrames >= arg2) 
                    {
                        loc2.gotoAndStop(arg2);
                    }
                    this.advanceChildClips(loc2, arg2);
                }
                ++loc1;
            }
            return;
        }

        protected /* override */ onContentReady(arg1): Boolean
        {
            if (loaderInfo) 
            {
                if (resourceInfo) 
                {
                    resourceInfo.data = loaderInfo;
                }
                this._appDomain = loaderInfo.applicationDomain;
            }
            return !(arg1 as Object /* flash.display.Sprite */ == null);
        }

        /* internal  */onUnloadHandler(arg1: Object /* flash.events.Event */): void
        {
            if (resourceInfo) 
            {
                Log.debug("unload:" + resourceInfo.name);
                if (loaderInfo) 
                {
                    loaderInfo.removeEventListener(flash.events.Event.UNLOAD, this.onUnloadHandler);
                }
            }
            return;
        }

        public /* override */ dispose(): void
        {
            super.dispose();
            return;
        }

        private /* var */_clip: Object /* flash.display.Sprite */;

        private /* var */_appDomain: Object /* flash.system.ApplicationDomain */;
    }
